#!/usr/bin/env bash

# check if $1 is empty
if [ -z "$1" ]
then
  # no argument passed
  AWS_PROFILE="$AWS_PROFILE" _awsd_prompt
else
  # argument passed, assume it's a profile name
  AWS_PROFILE="$AWS_PROFILE" _awsd_prompt "$@"
fi

selected_profile="$(cat ~/.awsd 2>/dev/null || touch ~/.awsd && cat ~/.awsd)"

if [ -z "$selected_profile" ]
then
  unset AWS_PROFILE
else
  export AWS_PROFILE="$selected_profile"
fi
